<?php
require_once PATH_NAME .'/utilities/dbquery.php';
require_once PATH_NAME .'/utilities/config.php';

//class usersModel extends dbConnect{
class usersModel{
	
	public function __construct(){
		new dbConnect();
	}
	
	public function login( $username, $password ){
		$query = "SELECT * FROM `tuser` WHERE publish = 1 and `username`='".$username."' and `password`='".md5($password)."'";
//		echo $query;exit;
		return dbQuery::queryFetchObject($query);			
	}
	
	public function saveRegCustomer( $data ){
		$sql = dbQuery::formatRequest($data);
		$q = "INSERT INTO `tuser` SET ".$sql;
//		echo $q;exit;
		dbQuery::query($q);
		return dbQuery::getInsertid( $result );
	}
	
	public function saveRegContract( $data ){
		$sql = dbQuery::formatRequest($data);
		$q = "INSERT INTO `tcontract` SET ".$sql;
		//echo 'SQL : '.$q;exit;
		dbQuery::query($q);
		return dbQuery::getInsertid( $result );
	}
	public function showAgentList( $user_id, $limits = '' ){
		$sql = "SELECT * FROM `tagent` WHERE publish = 1";
//		echo $sql;
		return dbQuery::queryFetchObject($sql);
	}
	public function showCustomerList( $user_id, $limits = '' ){
		$sql = "SELECT * FROM `tuser` WHERE publish = 1";
		//echo $sql;
		return dbQuery::queryFetchObject($sql);
	}
	public function showContractList( $user_id, $limits = '' ){
		$sql = "SELECT * FROM `tcontract` WHERE publish = 1";
		//echo $sql;
		return dbQuery::queryFetchObject($sql);
	}
	public function getUserById( $id = 0){
		$sql = "SELECT * FROM `tuser` WHERE  publish = 1 and `id` = $id";
		return dbQuery::queryFetchObject($sql);
	}
	public function editCustomer( $data ){
		$sql = dbQuery::formatRequest($data);
		$q = "UPDATE `tuser` SET ".$sql;
		//echo $q;exit;
		dbQuery::query($q);
	}
}
?>